
bl_info = {
    "name": "OSSL Menu",
    "author": "Tom Ernst",
    "version": (1, 0),
    "blender": (2, 93, 0),
    "location": "Topbar > OSSL Menu",
    "description": "OSSL Menu",
    "warning": "",
    "doc_url": "https://rOWLplay.net/blender/addons/ossl_menu.ashx",
    "category": "Development",
}

import bpy.types

class MenuFolder(bpy.types.Menu):
    bl_label = "OSSL Menu"

    menu_items = {}

    def draw(self, context):
        layout = self.layout

    @classmethod
    def append(self, fn):
        name = fn.__name__
        if (name in self.menu_items):
            self.remove(self.menu_items[name])
        super(bpy.types.Menu, self).append(fn)
        self.menu_items[name] = fn
        print(">>> added MenuItem >>> " + name)
    
    @classmethod
    def remove(self, fn):
        name = fn.__name__
        if (name in self.menu_items):
            self.menu_items.pop(name)
        super(bpy.types.Menu, self).remove(fn)
        print(">>> removed MenuItem >>> " + name)

class TOPBAR_MT_OSSL(MenuFolder):
    bl_idname = "TOPBAR_MT_OSSL"
    pass

def OSSL_menu(self, context):
    self.layout.menu("TOPBAR_MT_OSSL", text="OS/SL")

def manual_map():
    url_manual_prefix = "https://rowlplay.net/blender/addons/"
    url_manual_mapping = ( ("TOPBAR_MT_OSSL", "ossl_menu.ashx"), )
    return url_manual_prefix, url_manual_mapping

import ossl.util as util

def register():
    print("registering: OSSL Menu")
    bpy.utils.register_class(TOPBAR_MT_OSSL)
    bpy.types.TOPBAR_MT_editor_menus.append(OSSL_menu)
    bpy.utils.register_manual_map(manual_map)
    print("registered: OSSL Menu")

def unregister():
    print("unregistering: OSSL Menu")
    bpy.utils.unregister_manual_map(manual_map)
    bpy.types.TOPBAR_MT_editor_menus.remove(OSSL_menu)
    bpy.utils.unregister_class(TOPBAR_MT_OSSL)
    print("unregistered: OSSL Menu")

if __name__ == "__main__":
    import ossl.util as util
    util.reset_addon()
